package com.txf.simple.utils;

import android.widget.Toast;

import com.txf.simple.app.MyApp;


/**
 * 通用吐司，不会重复显示。
 *
 * @note Created by Chaosxing on 2016/10/27.
 */
public class ToastUtils {

    private static Toast toast = null;

    /**
     * 普通文本消息提示
     * @param text
     * @param duration
     *
     */
    public static void show(CharSequence text, int duration) {
        if (toast == null) {
            toast = Toast.makeText(MyApp.getContextInstance(), text, duration);
        } else {
            toast.setText(text);
            toast.setDuration(Toast.LENGTH_SHORT);
        }
        // 显示消息
        toast.show();
    }

    /**
     * 通过获取资源显示
     * @param resId
     * @param duration
     */
    public static void show(int resId, int duration) {
        if (toast == null) {
            toast = Toast.makeText(MyApp.getContextInstance(), resId, duration);
        } else {
            toast.setText(resId);
            toast.setDuration(Toast.LENGTH_SHORT);
        }
        toast.show();
    }

}
